/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package database;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Alejandro
 */
public class DatabaseDate extends DatabaseObject {

    public DatabaseDate() {
        value = new Date();
    }

    @Override
    public boolean isValid() {
        return (value != null);
    }

    @Override
    public void setValue(Object value) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
            this.value = (Date) sdf.parse((String) value);
        } catch(Exception e) {
            this.value = null;
        }
    }

    @Override
    public void setParam(String param, Object value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Object getParam(String param) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Object getValue() {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy");
            return sdf.format((Date) value);
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public String toString() {
        return getValue().toString();
    }
}
